//
//  TTQuickEstimateViewController.m
//  TaoTuo
//
//  Created by LG on 2020/8/10.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTQuickEstimateViewController.h"
#import <JXCategoryTitleView.h>
#import <JXCategoryIndicatorLineView.h>
#import <JXCategoryListContainerView.h>
#import "TTPassCertificateNumViewController.h"
#import "TTPassDiamondParamsViewController.h"

@interface TTQuickEstimateViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic, strong) NSArray *titles;

@end

@implementation TTQuickEstimateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"钻石极速估价";
    
    // 初始化JXCategoryTitleView
    self.titles = @[@"通过证书号估价", @"通过钻石4C估价"];
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 50)];
    self.categoryView.delegate = self;
    self.categoryView.titleColor = UIColorHex(666666);
    self.categoryView.titleSelectedColor = UIColorHex(333333);
    self.categoryView.titles = self.titles;
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.contentEdgeInsetLeft = 45*kScale;        // 左边距
    self.categoryView.contentEdgeInsetRight = 45*kScale;       // 右边距
    [self.view addSubview:self.categoryView];
    
    // 添加指示器
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = UIColorHex(9B71FF);
    lineView.indicatorHeight = 6;
    lineView.verticalMargin = 6;
    lineView.indicatorCornerRadius = 3;
    self.categoryView.indicators = @[lineView];
    
    
    // 初始化JXCategoryListContainerView并关联到categoryView
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
    self.listContainerView.frame = CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - StatusBarAndNavBar_Height - 50);
    [self.view addSubview:self.listContainerView];
    //关联到categoryView
    self.categoryView.contentScrollView = self.listContainerView.scrollView;
    
    self.categoryView.defaultSelectedIndex = self.defaultSelectedIndex;
    self.listContainerView.defaultSelectedIndex = self.defaultSelectedIndex;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
    
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    //侧滑手势处理
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);

}

- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
//    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    [self.listContainerView didClickSelectedItemAtIndex:index];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
    [self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}



#pragma mark - JXCategoryListContainerViewDelegate
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    if (index == 0) {
        return [[TTPassCertificateNumViewController alloc] init];
    }
    return [[TTPassDiamondParamsViewController alloc] init];
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}


- (UIView *)listView
{
    return self.view;
}



@end
